﻿using Furion.CMS.Application.Dto;
using Furion.CMS.Domain;
using Mapster;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furion.CMS.Application
{
    public class RoleProfile : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<RoleInfo, RoleDto>();

            config.ForType<RoleInfo, RoleDetailDto>()
                .Inherits<RoleInfo, RoleDto>();

            config.ForType<RoleInfo, RoleConfigureDetailDto>()
                .Inherits<RoleInfo, RoleDto>()
                .Map(dest => dest.Permissions, src => src.Permissions.Select(s => s.Code))
                //.AfterMapping((src, dest) =>
                //{
                //    var dependentResources = src.Permissions.Where(t => !string.IsNullOrEmpty(t.DependentResourceId)).Select(s => s.DependentResourceId);
                //    dest.Permissions = dest.Permissions.Union(dependentResources).Distinct().ToList();
                //})
                ;

            config.ForType<RoleCreateAndUpdateDto, RoleInfo>();
        }
    }
}
